package tuan_1;

import java.util.Scanner;

public class Test_SinhVien {
	public static void main(String[] args){
		Scanner nhap = new Scanner(System.in);
		if(args.length != 1){
			System.out.println("So luong tham so truyen vao khong hop le.");
			System.exit(0);
		}
		else{
			int n = Integer.parseInt(args[0]);
			SinhVien SV[] = new SinhVien[n];
			System.out.println("Nhap thong tin sinh vien:");
			for(int i=0;i<n;i++){
				System.out.println("Nhap vao thong tin sinh vien thu: "+(i+1));
				System.out.print("MSSV: ");
				int MS = nhap.nextInt();
				nhap.nextLine();
				System.out.print("Ho va ten: ");
				String Ten = nhap.nextLine();
				double Diem;
				do{
					System.out.print("Diem thi: ");
					Diem = nhap.nextDouble();
					if(Diem>10||Diem<0) System.out.print("Diem nhap vao khong hop le. Nhap lai.");
				}while(Diem>10||Diem<0);
				SV[i] = new SinhVien(MS, Ten, Diem);
				System.out.println();
			}
			System.out.println("Thong tin cua cac sinh vien");
			System.out.println("+------------+----------------------+----------+");
			System.out.println("| MSSV       | Ho va ten            | Diem thi |");
			System.out.println("+------------+----------------------+----------+");
			String leftAlignFormat = "| %-10d | %-20s | %-8.2f |\n";
			for(int i=0;i<n;i++){
				System.out.format(leftAlignFormat, SV[i].getMSSV(),SV[i].getHoTen(),SV[i].getDiemThi());
			}

			System.out.println("+------------+----------------------+----------+");
			
			int max = 0;
			int min = 0;
			double sum = 0;
			int count = 0;
			for(int i=0;i<n;i++){
				if(SV[i].getDiemThi() > SV[max].getDiemThi() ) max = i;
				if(SV[i].getDiemThi() < SV[min].getDiemThi() ) min = i;
				sum+=SV[i].getDiemThi();
				if(SV[i].getDiemThi() >=4) count++;
			}
			System.out.println("Sinh vien dat diem thap nhat: "+SV[min].getMSSV()+"\t"+SV[min].getHoTen()+"\t"+SV[min].getDiemThi());
			System.out.println("Sinh vien dat diem cao nhat: "+SV[max].getMSSV()+"\t"+SV[max].getHoTen()+"\t"+SV[max].getDiemThi());
			System.out.println("So luong sinh vien dat diem >=4: "+count);
			System.out.println("Diem trung binh cua ca nhom: "+sum/SV.length);
		}
	}
}
